import {action, observable, toJS} from 'mobx';
import * as EnableProcessAdditionAndSubtractionApi from "../apis/EnableProcessAdditionAndSubtractionApi";
import base from './../util/base';
import * as type from "../constants/type";

export  class EnableProcessAdditionAndSubtractionStore{
	@observable initialDatas_wait = []; // 高级搜索条件
	@observable updateuserid = "";
	@observable requestid = "";
	@observable nodeid = "";
	@observable nodeidspan = "";
	@observable userid = "";
	@observable useridspan = "";
	@observable signType  = "";
	constructor() {
		this.getDetailInfo = this.getDetailInfo.bind(this);
		this.setUpdatePerson=this.setUpdatePerson.bind(this);
		this.saveUpdateInfo=this.saveUpdateInfo.bind(this);
		this.setNodeid=this.setNodeid.bind(this);
		this.setRequestid=this.setRequestid.bind(this);
		this.RadioChange=this.RadioChange.bind(this);
		this.addNextNode=this.addNextNode.bind(this);

	}

	@action getDetailInfo(pa) {
		let params = {nodeid:this.nodeid,requestid:this.requestid};
		EnableProcessAdditionAndSubtractionApi.getDetailInfo(params).then(data => {
			this.nodeidspan = data.nodeidspan;
			this.userid = data.userid;
			this.useridspan = data.useridspan;

		});
		return this;
	}
	@action setUpdatePerson(val) {
			this.updateuserid = val;
	}
	@action setNodeid(val) {
		this.nodeid = val;
	}
	@action setRequestid(val) {
		this.requestid = val;
	}
	@action RadioChange(val){
		this.signType = val;
	}
	@action saveUpdateInfo(){
            if(this.updateuserid==""){
				WfForm.showMessage("请至少选择一名操作者!");
				return false;
			}
			let params = {nodeid:this.nodeid,requestid:this.requestid,updateuserid:this.updateuserid,beforeuserid:this.userid};
			EnableProcessAdditionAndSubtractionApi.SaveDetailInfo(params).then(data => {
				let {controlDialogVisible} = base.globalStore;
				controlDialogVisible(type.EnableProcessAdditionAndSubtraction,false);
				let {getNodeList} = base.freeWorkflowNewStore;
				getNodeList();
			});
	}
	@action addNextNode(){
		if(this.updateuserid==""){
			WfForm.showMessage("请至少选择一名操作者!");
			return false;
		}
		let {rightMenu,commonParam,baseParam} = base.globalStore;
		const { iscreate,authSignatureStr,authStr,wfTestStr,belongTest, selectNextFlowPattern} = toJS(commonParam);
		const { iscnodefree,isFree,freeNode = {} ,isAllowNodeFreeFlow} = toJS(rightMenu);
		const {nodeid,workflowid,requestid,f_weaver_belongto_userid,f_weaver_belongto_usertype} = toJS(baseParam);
		let params = {requestid:this.requestid,nodeid:this.nodeid,isParallel:0,operatorids:this.updateuserid,workflowid:workflowid,signType:2,nextNodeEditPurview:2,allowModify:true,nodetype:1};
		EnableProcessAdditionAndSubtractionApi.addNextNode(params).then(data => {
			let {controlDialogVisible} = base.globalStore;
			controlDialogVisible(type.EnableProcessAdditionAndSubtraction,false);
			let {getNodeList} = base.freeWorkflowNewStore;
			getNodeList();
		});
	}
}
